<!-- 取消售后 -->
<template>
  <el-dialog v-model="dialogVisible" title="取消售后" width="35%" top="30vh" class="base_dialog" @open="resetForm(formRef)">
    <el-form ref="formRef" :model="form" :rules="rules" label-width="80px">
      <el-form-item label="取消原因" prop="reason">
        <el-input v-model="form.reason" type="textarea" clearable resize="none" />
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button type="primary" @click="submitForm(formRef)">确定</el-button>
        <el-button @click="dialogVisible = false">取消</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup>
import { ref, reactive, defineEmits, defineExpose } from "vue";

const emit = defineEmits(["cancelAfterSale"]);

const dialogVisible = ref(false);

function show() {
  dialogVisible.value = true;
}

defineExpose({ show });

const formRef = ref(null);

const form = reactive({
  // amount: null,
  reason: null,
});

const rules = {
  reason: [
    {
      required: true,
      message: "请输入取消原因",
      trigger: "blur",
    },
  ],
};

const submitForm = (formEl) => {
  if (!formEl) return;
  formEl.validate((valid, fields) => {
    if (valid) {
      emit("cancelAfterSale", form);
      dialogVisible.value = false
    }
  });
}

const resetForm = (formEl) => {
  if (!formEl) return;
  formEl.resetFields();
}
</script>
